package com.wc.算法提高课.C第三章_图论.单源最短路的综合应用.通信线路;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Deque;
import java.util.LinkedList;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/10/10 22:39
 * @description https://www.acwing.com/problem/content/description/342/
 */
public class Main {
    /**
     * 思路：双端队列 + 二分
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 1010, M = 20010, INF = 0x3f3f3f3f;
    static int[] h = new int[N], e = new int[M], ne = new int[M], w = new int[M];
    static int[] dist = new int[N];
    static boolean[] st = new boolean[N];
    static Deque<Integer> q = new LinkedList<>();
    static int n, m, k, idx = 1;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        k = sc.nextInt();
        while (m-- > 0) {
            int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();
            add(a, b, c);
            add(b, a, c);
        }
        int l = 0, r = (int) 1e6 + 1;
        while (l < r) {
            int mid = l + r >> 1;
            if (check(mid)) r = mid;
            else l = mid + 1;
        }
        if (r == (int) 1e6 + 1) r = -1;
        out.println(r);
        out.flush();
    }

    static boolean check(int mid) {
        Arrays.fill(dist, 1, n + 1, INF);
        Arrays.fill(st, 1, n + 1, false);
        dist[1] = 0;
        q.add(1);
        while (!q.isEmpty()) {
            int t = q.pollFirst();
            if (st[t]) continue;
            st[t] = true;
            for (int i = h[t]; i > 0; i = ne[i]) {
                int j = e[i], v = w[i] > mid ? 1 : 0;
                if (dist[j] > dist[t] + v) {
                    dist[j] = dist[t] + v;
                    if (v == 0) q.addFirst(j);
                    else q.addLast(j);
                }
            }
        }
        return dist[n] <= k;
    }

    static void add(int a, int b, int c) {
        e[idx] = b;
        w[idx] = c;
        ne[idx] = h[a];
        h[a] = idx++;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
